Skip to content

Refactor BaseMetricService (#17) - #37

Open
sonnenco wants to merge 9 commits into
deyna256:mainfrom
sonnenco:17
Open

Refactor BaseMetricService (#17)#37
sonnenco wants to merge 9 commits into
deyna256:mainfrom
sonnenco:17

Conversation

@sonnenco

Copy link
Copy Markdown

Issue

#17

Changes

  1. Refactored /backend/domain/services/base.py from BaseMetricService class with static methods to standalone functions.

  2. Removed import and use of BaseMetricService class from backend/domain/services/abandoned_problems_service.py due to lack of invocation of _deduplicate_problems or _filter_successful_submissions.

  3. Updated the import statements and use of BaseMetricService in several files to point to the standalone functions, including:

* backend/domain/services/tags_service.py
* backend/domain/services/difficulty_distribution.py
* backend/domain/services/__init__.py
* backend/tests/unit/base_metric_service/test_deduplicate_problems.py
* backend/tests/unit/base_metric_service/test_filter_successful_submissions.py

Testing

The following tests come out identical to the main branch:

  • Backend: linting, type checking, tests
  • Frontend: linting, type checking, build

Please let me know if there are any questions or concerns.

…ass with static methods to functions. Updated the related import statements and function invokation lines in backend/domain/services files, including tags_service.py, difficulty_distribution.py, and abandoned_problem_service.py.
…ssions.py files to correctly call the functions in backend/domain/services/base.py. Change due to shift from BaseMetricService class with static methods to standalone functions.

@deyna256 deyna256 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did a great job! But pulling private functions out of the services package seems very strange to me. I have an idea about refactoring the private functions - let's make an abstraction which will encapsulate a bunch of Problem objects. It can have both of our private methods to do some filtering with the Problem objects it has. What do you think?

@sonnenco

Copy link
Copy Markdown
Author

Hello @deyna256 - thank you for the feedback. I can adjust, but would like to confirm my understanding of your proposed solution before I make further changes:

Current

  • Private functions declared in base.py
  • Private functions are imported for use into other files in the Services package and test suite

Future

  • Create a class in base.py that contains both of the non-static methods and initializes attributes for _submissions and _problems
  • Methods can access these attributes to perform deduplication and filtering capabilities within the class
  • Use the new class in the other files in the Services package and test suite

Please let me know if I've missed anything or misunderstood.

@deyna256

Copy link
Copy Markdown
Owner

@sonnenco exactly! let's do it!

@sonnenco
sonnenco requested a review from deyna256 February 18, 2026 01:26

@deyna256 deyna256 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonnenco you did a great job! Just fix some issues and we are good to merge it!

Comment thread backend/domain/services/base.py Outdated

@staticmethod
def _deduplicate_problems(submissions: List[Submission]) -> List[Submission]:
def _deduplicate_problems(self) -> List[Submission]:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python, prefixing a method name with an underscore (_) is a convention used to signal that the method is intended to be private (i.e., not part of the public API). But in our case methods: _deduplicate_problems and _filter_successful_submissions are public API of SubmissionProcessor class, rename them

Comment thread backend/domain/services/base.py Outdated

from backend.domain.models.codeforces import Submission

class SubmissionProcessor:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we name the class like this? A developer cannot understand its meaning if they don't read its methods, so we should rename it.

Comment thread backend/domain/services/base.py Outdated
@deyna256

Copy link
Copy Markdown
Owner

@sonnenco also you need to fix the checks: Backend Tests, Backend Type Checker

…m private to public functions. Retain original submissions and perform operations on working copy.
…me in ARCHITECTURE.md. Removed class reference in __init__.py as SubmissionCollection is a helper.
@sonnenco

Copy link
Copy Markdown
Author

backend testing

  • just test passes required test coverage, very similar results to main branch
  • just check states "all checks passed" (runs lint + typecheck)

frontend testing

  • just typecheck states "npx tsc --noEmit"
  • just lint doesn't come back with anything

Docker container builds fine locally (just build) and is accessible from http://localhost:3000 (just up).

Awaiting validation from workflows to double check results.

@sonnenco

Copy link
Copy Markdown
Author

Thank you for your patience @deyna256. I've addressed the feedback as best I can. Re-requesting review.

@sonnenco
sonnenco requested a review from deyna256 February 19, 2026 00:39
Comment thread backend/domain/services/base.py Outdated
…dification within class methods. Updated method calls in associated backend services and testing files.
@sonnenco
sonnenco requested a review from deyna256 February 20, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants